class_name UnitTank
extends UnitFlyMagic


@onready var missle_shoot_point: Marker2D = $ViewRoot/MissleShootPoint


func shoot_magic():
	if not attack_target: return
	
	shoot_tank_missle()
	

func process_face():
	return


func shoot_tank_missle():
	if not attack_target: return
	
	var target_unit = attack_target as UnitBase
	var target_position = missle_shoot_point.global_position
	#var target_dir = (attack_target.ray_cast_point.global_position - missle_shoot_point.global_position).normalized()
	var bullet = (ResourceManager.get_resource("particle_tank_missle") as PackedScene).instantiate() as ParticleTankMissle
	
	var config = unit_data.config 
	bullet.attack = config.main_attack
	bullet.critical_rate = config.main_critical_attack_rate
	bullet.critical_bonus = config.main_critical_attack_bonus
	bullet.knockback = config.main_attack_knockback
	bullet.sender = self
	bullet.dir = get_face() * Vector2.RIGHT
	bullet.speed = 80
	bullet.life_time = 5.0
	
	if config.main_attack_cam_shake:
		bullet.hit_cam_shake_strength = config.main_attack_cam_shake_intensity
		bullet.hit_cam_shake_duration = config.main_attack_cam_shake_duration
	
	level.particles_parent.add_child(bullet)
	bullet.global_position = target_position
	bullet.set_is_enemy(self.is_enemy)


func play_magic_animation():
	animation_player.play("magic")
	
